package com.film.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import com.film.dao.HobbyDao;
import com.film.domain.Hobby;
import com.film.rowMapper.HobbyRowMapper;
import com.film.util.DBUtil;

public class HobbyDaoImpl implements HobbyDao {
	private JdbcTemplate temp = new JdbcTemplate(DBUtil.getDataScorse());
	@Override
	public List<Hobby> select(int u_id) {
		String sql="SELECT * FROM user t1,hobby t2,user_hobby t3 WHERE t1.u_id=t3.u_id and t2.h_id=t3.h_id AND t1.u_id=?";
		return temp.query(sql, new HobbyRowMapper(),u_id);
	}
	@Override
	public List<Hobby> selectAllHobby() {
		String sql = "SELECT * FROM hobby";
		return temp.query(sql, new HobbyRowMapper());
	}
	@Override
	public int insertUserHobby(int uId, int hobbyId) {
		String sql = "insert into user_hobby values(default,?,?)";
		return temp.update(sql,uId,hobbyId);
	}
	@Override
	public int deleteByiduh(int u_id) {
		String sql = "DELETE  FROM user_hobby WHERE u_id=?";
		return temp.update(sql,u_id);
	}

}
